let timer
function getDuanMa() {
    // 手机号
    let str = $('#mobile').val().trim();
    if (str) {
        var myreg = /^1([3456789])\d{9}$/;
        if (!myreg.test(str)) {
            alert('手机号格式不正确');
        } else {
            let phoneNumEnc = window.btoa(str);
            $.ajax({
                type: 'GET',
                url: httpUrl+'/api/v1/open/refundMsg?phoneNumEnc='+phoneNumEnc,
                success: function(result) {
                    if(result.code=='10000'){
                        $(".huo").hide();
                        $(".yi").show();
                        var countdown = 59;  // 设置倒计时为 59 秒
                        if(timer){
                            clearTimeout(timer)
                        }
                        timer = setInterval(function() {
                            $(".yi").text("已发送(" + countdown + ")");
                            countdown--;
                            if (countdown < 0) {
                                clearInterval(timer);
                                $(".huo").show();
                                $(".yi").hide();
                            }
                        }, 1000);
                    }else{
                        setTimeout(()=>{
                            alert(result.msg)
                        },50)
                    }
                },
                error: function(xhr, status, error) {
                    setTimeout(()=>{
                        alert('发送失败，请稍后再试。');
                    },50)

                }
            });
        }
    } else {
        alert('请先输入下单手机号');
    }
}
function toRefund(){
    let aliAccount = $('#aliAccount').val().trim();
    let aliName = $('#aliName').val().trim();
    let mobile = $('#mobile').val().trim();
    let code = $('#code').val().trim();
    var codeDiv = document.querySelector('.model');
    if (!aliAccount || !aliName || !mobile ||!code){
        alert("请先填入完整信息");
    }else{
        var myreg = /^1([3456789])\d{9}$/;
        if (!myreg.test(mobile)) {
            alert('手机号格式不正确');
        }else{
            let phoneNumEnc = window.btoa(mobile);
            let params={
                aliAccount:aliAccount,
                aliName: aliName,
                phoneNumEnc:phoneNumEnc,
                code: code
            }
            console.log(params)
            codeDiv.style.display = 'block';
            $.ajax({
                type: 'POST',
                url: httpUrl+'/api/v1/open/refundOrder',
                contentType: 'application/json',
                data: JSON.stringify(params),
                success: function(result) {
                    codeDiv.style.display = 'none';
                    if(result.code=='10000'){
                        setTimeout(()=>{
                            alert('退款申请成功请耐心等候,如有问题可联系在线客服')
                        },50)
                    }else{
                        setTimeout(()=>{
                            alert(result.msg)
                        },50)
                    }
                },
                error: function(xhr, status, error) {
                    codeDiv.style.display = 'none';
                    setTimeout(()=>{
                        alert('网络波动，请稍后再试。');
                    },50)

                }
            });

        }
    }

}
